home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1998 March / Macworld (1998-03) (Disk 1).dmg / Shareware World / Utilities / Text Processing / Alpha / Help / ElecCompletions Help < prev    next >
Encoding:
Text File  |  1997-12-01  |  16.7 KB  |  448 lines  |  [TEXT/ALFA]

  1. ## 
  2.  # ###################################################################
  3.  #  Vince's Additions - an extension package for Alpha
  4.  # 
  5.  #  FILE: "ElecCompletions Help"
  6.  #                                    created: 1/8/97 {2:24:21 pm} 
  7.  #                                last update: 1/12/97 {5:46:17 pm} 
  8.  #  Author: Vince Darley
  9.  #  E-mail: <darley@fas.harvard.edu>
  10.  #    mail: Division of Engineering and Applied Sciences, Harvard University
  11.  #          Oxford Street, Cambridge MA 02138, USA
  12.  #     www: <http://www.fas.harvard.edu/~darley/>
  13.  #  
  14.  # Copyright (c) 1997  Vince Darley
  15.  # 
  16.  # ###################################################################
  17.  ##
  18.  
  19. If you want basic help/tutorial information, do the following: when 
  20. you're in a mode for which you want a tutorial on electric completions,
  21. select 'Completions Tutorial' from the 'Current mode' menu.  Follow 
  22. the instructions there.
  23.  
  24. Recent changes:
  25.  
  26. The code has been split into separate packages.  The better templates code 
  27. is now optional --- it is slow on slow machines so some people prefer not
  28. to use it, but still like all the electric completions etc.  The problem
  29. is that the standard template code lacks some of the more advanced features
  30. of my version.
  31.  
  32. You can modify the following preferences using the 
  33. 'Config->Global->Flags->Electrics' menu item:
  34.  
  35.     • useElectricMenu --- use electric template menu 
  36.     • showElectricsInMenu --- show electric completions in menu 
  37.     • showElectricKeysInMenu --- show electric key bindings in menu
  38.     • modeSpecificElecTab --- use mode-specific electric tab 
  39.     • electricTab --- use electric tab 
  40.     • templateStopColor --- colour of template stops 
  41.     • listPickIfMultExpds --- similarly for expansions 
  42.     • ElectricFillers --- The format of the template stops:
  43.           0 = just use bullets
  44.           1 = use bullets but signal the name in the status window
  45.           2 = insert names into the window with the bullets
  46.           3 = insert names and highlight into the window with the bullets
  47.     • maxTemplateNesting--- level of nesting we allow before clearing 
  48.  
  49. The electric menu contains a 'Templates' sub-menu, which contains global 
  50. templates stored in the variable 'univ::MenuTemplates', and mode-specific
  51. templates stored in variables ${mode}Templates.  The format of these 
  52. variables is a list of names, which correspond to procedures when prepended 
  53. with 'file::'.  You can add new items by using the menu item.
  54.  
  55.           Templates
  56.  
  57. Many of the routines in Vince's Additions allow you to insert templates for 
  58. 'for' loops, '\begin...\end environments', file headers, function comments, 
  59. and even entire documents.  This section details the features of Vince's 
  60. Additions which allow you to do that.  Here's an example of a 'for' template
  61. in C++ mode (created just by typing 'for<cmd-Tab>'):
  62.  
  63.     for (•<init>;•<test>;•<increment>){
  64.         •<loop body>
  65.     }
  66.     •
  67.  
  68. Once a template has been inserted, it will often contain a number of 
  69. 'place-markers' or 'template-stops' at each of which you will most likely 
  70. wish to enter some text/code.  You can jump backwards and forwards amongst 
  71. these stops using a set of key bindings.  You have a choice between two 
  72. basic sets (you select using the 'Electric Bindings' dialog):
  73.  
  74.     Operation               Standard Bindings         Alternative Set
  75.  
  76.     "Next Stop Or Tab"       Tab                       ctrl-j      
  77.     "Complete"               cmd-Tab                   cmd-Tab     
  78.     "Expand"                 cmd-Space                 Tab 
  79.     "Prev Stop"              shift-Tab                 shift-ctrl-j        
  80.     "Real Tab"               opt-Tab                   opt-Tab
  81.     "nth Stop"               ctrl-Tab                  ctrl-opt-j          
  82.     "Clear All Stops"        shift-ctrl-Tab            shift-ctrl-opt-j            
  83.  
  84. Furthermore you can redefine any of these bindings using that same
  85. dialog.
  86.  
  87. You have a choice between four different formats for the visual appearance 
  88. of the template-stops.  They are usually signified by a bullet '•', but 
  89. more elaborate methods are supported.  These templates may be nested 
  90. without any extra effort on your part.  Most of this code is contained in 
  91. the file "univTemplates.tcl", although all the bindings and initialisation 
  92. are in "univBindings.tcl".
  93.  
  94. Look at the new 'electric' menu for a list of these bindings, together 
  95. with some other functions.
  96.  
  97. ================================================================================
  98.  
  99.           Completions
  100.  
  101. I've now written a unified collection of procedures to address command 
  102. completion, code indentation, electric-code generation, word completion and 
  103. related facilities (incorporating my old TeX-reference completion for 
  104. example). 
  105.  
  106. Here's a typical example from TeX mode, I type:
  107.  
  108.     for an explanation of this phenomenon,
  109.     please refer to Fig<cmd-Tab>
  110.     
  111. The <cmd-Tab> signifies that Vince's Additions should try to complete the 
  112. currently typed text.  In this case the completion is:
  113.  
  114.     for an explanation of this phenomenon,
  115.     please refer to Figure~\ref{fig-
  116.     
  117. If I hit <cmd-Tab> again, Vince's Additions tries to search for TeX 
  118. '\labels' which begin with 'fig-' to insert the first such label
  119. it finds into the text:
  120.  
  121.     for an explanation of this phenomenon,
  122.     please refer to Figure~\ref{fig-heat-vs-time}
  123.     
  124. If this is the wrong one, I can keep hitting <cmd-Tab> until I reach the 
  125. correct completion:
  126.  
  127.     for an explanation of this phenomenon,
  128.     please refer to Figure~\ref{fig-explanation}
  129.     
  130. Here's an example from C/C++ modes. I type 'for<cmd-Tab>' and get:
  131.  
  132.     for (;•;•){
  133.         •
  134.     }
  135.  
  136. This works at any current level of indentation, and the bullet marks '•' 
  137. are placemarkers.  You can just press 'Tab' (without 'cmd') to jump from 
  138. one to the next.
  139.  
  140. These facilities are activated as follows:
  141.  
  142. •    Tab --- plain - either 'indent' or 'next template mark'
  143.             cmd   - complete the current text.
  144.             opt   - insert a real tab.
  145.                         
  146. So, pressing Tab by default will _not_ necessarily insert a tab, rather it 
  147. will indent the current line of code to the correct indentation level to 
  148. match the code around it.  
  149.  
  150.             Types of completion
  151.  
  152.  
  153. Command-Tab has a number of different meanings, which will be explained 
  154. below.  Completions are listed in order of precedence.
  155.  
  156.               User completion: 
  157.  
  158. all entries defined in the array 'userCompletions' are checked and inserted 
  159. if appropriate.  This is useful to make 'vmd' turn into 'Vince Darley', or 
  160. 'www' into my home-page url, or ...
  161.     
  162. User completions are active in all modes, and take precedence over all 
  163. other completion types.
  164.  
  165.               Context sensitive completion: 
  166.  
  167. Context sensitive completions are mode dependent.  In some modes you 
  168. can tell relatively easily from the context whether a particular 
  169. 'word' is a variable or procedure name or...  If different completion
  170. procedures are useful for different types of word, then they are 
  171. checked next.  For instance, in Tcl mode, a word beginning with '$',
  172. or preceded by 'set' or 'global' is a variable name.  It should 
  173. therefore be completed preferentially as a variable, rather than
  174. being expanded as a command.  E.g. $str should normally not be
  175. expanded to '$string ...' since it's clearly not the command 'string' 
  176. that the user is trying to type.  
  177.  
  178.               Command completion: 
  179.  
  180. For instance: type 'str<cmd-tab>' and it is completed to 'string' (in Tcl 
  181. mode).  If there are multiple possibilities then the longest unique prefix 
  182. is inserted.
  183.     
  184. The available completions are mode dependent, and stored as a large string 
  185. in the variable ${mode}cmds.  They must be stored alphabetically, be 
  186. separated by whitespace, and have a single space at the beginning and end 
  187. of the large string.
  188.  
  189. Here is the default value for Tcl mode:
  190.  
  191.     set Tclcmds { append array catch close concat continue elseif error
  192.     for foreach format lindex lsearch lsort regexp regsub
  193.     rename return string switch while }
  194.  
  195.               Ensemble completion: 
  196.  
  197. type 'string co<cmd-Tab' and this is both completed to 'string compare' and 
  198. an electric template is inserted for the arguments of this two part 
  199. command.  Useful for any case in which the word before last is the command, 
  200. and the word just before is part of a refinement of that command, in any 
  201. situation for which a number of further arguments will be filled in.
  202.     
  203.               Electric code template generation: 
  204.  
  205. type 'for<cmd-tab>' and a complete template for code is generated (example 
  206. for C mode):
  207.     
  208.     for (;•;•){
  209.         •
  210.     }
  211.  
  212. You can move from one template mark '•' to the next with, plain 'Tab' - 
  213. I automatically sense whether a template insertion is in progress or
  214. not and interpret tab accordingly.
  215.  
  216. These are again mode dependent. Each is stored individually as an element 
  217. of the array ${mode}electrics, so, for instance the above electric code is 
  218. generated by:
  219.  
  220.     set Celectrics(for) " (••;••;••)\{\n\t••\n\}\n••"
  221.  
  222. Note how the bullets are double in the definition.  You can actually place 
  223. an explanatory bit of text between pairs of bullets.  This is then used as 
  224. a hint to the user:
  225.  
  226.     set Celectrics(for) " (•start•;•test•;•increment•)\{\n\t•body•\n\}\n••"
  227.  
  228.               Class name completion: 
  229.  
  230. In C++ mode, when entering a class definition, the class name occurs 
  231. multiple times.  To save entering all of these, this completion will
  232. fill them all in for you.  It works like this: type 'class<cmd-tab>'
  233.  
  234.     class •<object name> : public •<parent> {
  235.       public:
  236.         •<object name>(•<args>);
  237.         ~•<object name>(void);
  238.     
  239.     };
  240.     •
  241.  
  242. Now type the class name, say 'toaster', followed by <cmd-tab>.  This
  243. will result in:
  244.  
  245.     class toaster : public •<parent> {
  246.       public:
  247.         toaster(•<args>);
  248.         ~toaster(void);
  249.     
  250.     };
  251.     •
  252.  
  253. i.e. each occurrence of the electric stop 'object name' has been 
  254. filled in correctly.  This feature may be easily extended to more
  255. complex examples.
  256.  
  257.               TeX reference completion: 
  258.  
  259. type '\ref<cmd-Tab>' and the command is automatically completed with the 
  260. name of a nearby \label{}.  Repeated <cmd-Tab> keypresses will cycle 
  261. through all \label's.  Further, these commands chain together, so typing 
  262. '\eqr<cmd-Tab>' will complete the \eqref and continue to fill in a nearby 
  263. label!
  264.  
  265. These were explained above.  Note that the reference completions can be 
  266. instigated by command completion on, 'Fig' 'Chap' 'Eq.'  'Sec', ...  which 
  267. insert the standard label prefix 'fig:' 'chap:' 'eq:' 'sec:' as 
  268. appropriate.  If you complete with no prefix, then any label will match; if 
  269. you have a prefix then only those which match will be suggested.
  270.  
  271.               TeX citation completion.  
  272.  
  273. Type '\cite{Darley19<cmd-Tab>' and the command is completed with a matching 
  274. citation entry from one of your '.bib' database files.  If there are 
  275. multiple possibilities, then you are prompted with a list from which to 
  276. choose.  (Note: if you find the selection box a bit narrow, it is possible
  277. to edit Alpha using ResEdit to increase its size).  Depending upon the
  278. value of a TeX flag, the list can include the titles of each choice,
  279. making it more obvious to you which is correct.
  280.  
  281.               TeX environment completion: 
  282.  
  283. \begin{} \end{} pairs with synchronisation of the parameter, and template 
  284. generation of the body.
  285.  
  286. You can complete '\begin<cmd-Tab>' followed by 'equ<cmd-Tab>' to the
  287. following:
  288.  
  289.     \begin{equation}
  290.         •
  291.         \label{eq:•}
  292.     \end{equation}
  293.     •
  294.  
  295. You have a choice between the double-completion, as above, or just typing
  296. '\begin{equation}<cmd-Tab>' which will do the job in one go.
  297.  
  298. Similar things work for 'itemize' 'enumerate' etc.  Of particular use
  299. are the completions for 'figure' environments, from which you can enter
  300. ordinary figures, floating figures, and a large number of sub-figure 
  301. configurations (2 figures side-by-side, a block of 4,...).  For instance,
  302. a handful of key-presses will give you this:
  303.  
  304.     \begin{figure}
  305.         \centering
  306.         \subfigure[•“subfig caption”]{\label{fig:•}%
  307.             \includegraphics[width=\figstwo]{•“graphics file”}}\goodgaptwo
  308.         \subfigure[•“subfig caption”]{\label{fig:•}%
  309.             \includegraphics[width=\figstwo]{•“graphics file”}}\\
  310.         \subfigure[•“subfig caption”]{\label{fig:•}%
  311.             \includegraphics[width=\figstwo]{•“graphics file”}}\goodgaptwo
  312.         \subfigure[•“subfig caption”]{\label{fig:•}%
  313.             \includegraphics[width=\figstwo]{•“graphics file”}}%
  314.         \caption•“[short caption for t.o.f.]”{•“caption”}
  315.         \label{fig:•}
  316.     \end{figure}
  317.     •
  318.  
  319. For these to work, you must use the correct LaTeX packages (graphics, 
  320. floatingfigure or subfigure as appropriate, although the code will 
  321. automatically insert the correct 'usepackage' specifications for you if 
  322. desired), and you may need the following definitions in your LaTeX 
  323. preamble:
  324.  
  325.     \newlength{\goodspace}
  326.     \newlength{\goodspacethree}
  327.     \newlength{\goodspacefour}
  328.     \newlength{\figstwo}
  329.     \newlength{\figsthree}
  330.     \newlength{\figsfour}
  331.     
  332.     \setlength{\goodspace}{\subfigtopskip+\subfigbottomskip}
  333.     \setlength{\goodspacethree}{\goodspace}
  334.     \setlength{\goodspacefour}{\goodspace*\real{0.6}}
  335.     
  336.     \newcommand{\goodgap}{\hspace{\goodspace}}
  337.     \newcommand{\goodgaptwo}{\goodgap}
  338.     \newcommand{\goodgapthree}{\hspace{\goodspacethree}}
  339.     \newcommand{\goodgapfour}{\hspace{\goodspacefour}}
  340.     
  341.     \setlength{\figstwo}{(\linewidth-\goodspace)/2-1pt}
  342.     \setlength{\figsthree}{(\linewidth-\goodspace *2)/3-1pt}
  343.     \setlength{\figsfour}{(\linewidth-\goodspace *\real{1.8})/4-1pt}
  344.  
  345. These allow good alignment and spacing for most subfigure combinations
  346. without the need for manual intervention.  
  347.  
  348. Some environments can contain an arbitrary number of items.  In this case, 
  349. hitting 'shift-option-i' will add an item.  Here we turn this:
  350.  
  351.     \begin{description}
  352.         \item[First one] here's the description
  353.         
  354.         \item[•“name”] •“description”
  355.         
  356.     \end{description}
  357.     •
  358.  
  359. into:
  360.  
  361.     \begin{description}
  362.         \item[First one] here's the description
  363.         \item[•] •
  364.         
  365.         \item[•“name”] •“description”
  366.         
  367.     \end{description}
  368.     •
  369.  
  370. Similar entries work correctly for itemised, enumerated, aligned,... 
  371. environments.
  372.  
  373.               File-name completion:
  374.  
  375. Useful for Shel mode, this allows you to type a partial directory or 
  376. filename and hit cmd-Tab to have it extended as much as possible.
  377.  
  378.               Tcl Variable Completion:
  379.  
  380. Tcl variables are often referenced with '$var' or just 'var' or '${var}'.  
  381. You can complete between any of these types.  A local search for a match is 
  382. done and the closest match inserted.  Again you can cycle through other 
  383. matches with <cmd-Tab>
  384.  
  385.               Word Completion: 
  386.  
  387. if none of the above succeeded then the current word is completed to copy 
  388. nearby words (variable names) in the file.  Again, repeated presses will 
  389. cycle through other possibilities.
  390.  
  391. In any form of text in any mode, if no mode-specific completion matches, 
  392. then any local word can match, complete and be cycled through as usual.
  393.  
  394.             Template insertion
  395.  
  396. You'll notice in a lot of the above examples that bullets '•' are inserted 
  397. into the text.  In fact the user has a choice of four different levels of 
  398. interaction with the template insertion procedures.  You can change this 
  399. using the universal preferences dialog (in the config menu).  You can move
  400. from one insertion point to the next using the 'tab' key; move backwards 
  401. with 'shift-tab' and jump to any insertion point with 'ctrl-tab'.  If you 
  402. don't like these key bindings, an alternative set is available by a change 
  403. in the universal preferences.  You can also choose the colour of the
  404. inserted bullets/prompts.
  405.  
  406.             The Electric Menu
  407.  
  408. By default all items in the ${mode}electrics array are inserted into a new 
  409. menu.  This allows you to insert them, and get a feel for a small number 
  410. of the completions which exist.  Also at the bottom of the menu are items 
  411. for each of the standard key bindings these routines use, to help you to 
  412. remember them.
  413.  
  414.             Completion feedback
  415.  
  416. Help me to help you!
  417.  
  418. Completions for some common items just don't currently exist.  So if you 
  419. try to complete something and it doesn't work, why not write a completion 
  420. for it?  Once you have assembled a few, mail them to me (preferably 
  421. binhex'd, since bullets '•' don't travel well by ASCII mail).  I'd
  422. particularly like completions for other modes.
  423.  
  424.             Speed
  425.  
  426. Alpha has some limitations which means some aspects of Vince's Additions
  427. are a little bit slow (on low-end machines, at least).
  428.  
  429. Two things you can do to alleviate this: first, in modes for which Tab (or 
  430. ctrl-j under the alternative bindings) ALWAYS means to go the next template 
  431. stop and never means to indent the current line, define a new mode variable 
  432. 'tabNeverIndents' by adding the following line to your "prefs.tcl":
  433.   
  434.     newPref f tabNeverIndents 1 MODE
  435.  
  436. where 'MODE' is 'TeX', 'Java', 'HTML' or whatever.  You'll need to add one
  437. such line for each relevant mode.
  438.  
  439. The second thing you can do is to mail Pete Keleher to ask for new features 
  440. and fixes which will improve this problem.  What is needed is:
  441.   (i) GetTMarkPos ?-w win? name  --- find pos of Tmark 'name' in window
  442.   (ii) GetTMarks ?-w win?        --- list Tmarks in given window only
  443.   (iii) curWin ?-f?              --- return uppermost window name (full path)
  444.   (iv) a bug fix so 'GetTMarks' doesn't think non-file windows are in 
  445.   Alpha's HOME directory.
  446.   
  447. ================================================================================
  448.